/*
 * (c) 2007, Delsi Interactive
 * User: sebastian.lucas
 * Date: 20/05/2007
 * Time: 09:11 p.m.
 */

using System;
using System.Drawing;
using System.Windows.Forms;

namespace CSE
{
	/// <summary>
	/// Description of DuplicateClip.
	/// </summary>
	public partial class DuplicateClip : Form
	{
		/*
		 * Constants
		 */
		public static readonly string TXT_SUFLIX = "_copy";
		
		/*
		 * Constructor
		 */
		public DuplicateClip()
		{
		    MainForm.self.Enabled = false;
		    
			InitializeComponent();
			
			this.Location = new Point (MainForm.self.Location.X + (MainForm.self.Width / 2) - (this.Width / 2),
			                           MainForm.self.Location.Y + (MainForm.self.Height / 2) - (this.Height / 2));
			
			this.txtName.Text = ((Clip)MainForm.libSel.Tag).name + TXT_SUFLIX;
			
			this.Show(MainForm.self);
			this.Focus();
		}
		
		/*
		 * UnloadMe
		 */
		private void UnloadMe ()
		{
			MainForm.self.Enabled = true;
			this.Dispose();
			MainForm.nc = null;
		}
		
		/*
		 * Ok
		 */
		void BtnOkClick(object sender, EventArgs e)
		{
			Clip c = ((Clip)MainForm.libSel.Tag);
			
			if (!Workspace.IsValidClipName(this.txtName.Text))
            {
                return;
            }
			
			MainForm.libSel = MainForm.libClipsLibrary;
			TreeNode t = Workspace.NewClip(c.type, this.txtName.Text, c.usebitmap);
			((Clip)t.Tag).Copy(c);
			
			Workspace.SortLibrary();
			
			MainForm.libSel = t;
			
			UnloadMe();
		}
		
		/*
		 * Cancel
		 */
		void BtnCancelClick(object sender, EventArgs e)
		{
			UnloadMe();
		}
	}
}
